from sqlalchemy import create_engine
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy import Column,String,Integer,JSON,Text
from sqlalchemy.orm import sessionmaker

engine = create_engine("mysql+pymysql://root:root@localhost:3306/jiheflask?charset=utf8")
Base=declarative_base()

class Dishes(Base):
    __tablename__='xiachufang_dishes'

    dish_id=Column(Integer,primary_key=True)
    three_class_name=Column(String(255),nullable=False)
    dish_name = Column(String(255), nullable=False)
    dish_pic_small_src = Column(String(255), nullable=False)
    dish_pic_big_src = Column(String(255), nullable=False)
    dish_href = Column(String(255), nullable=False)

    def to_json(self):
        dict = self.__dict__
        if "_sa_instance_state" in dict:
            del dict["_sa_instance_state"]
        return dict
class Products(Base):
    __tablename__ = 'promote_products'

    id = Column(Integer, primary_key=True)
    bussiness_type = Column(String(255), nullable=False)
    line = Column(String(255), nullable=False)
    type = Column(String(255), nullable=False)
    smell_type = Column(String(255), nullable=False)
    name = Column(String(255), nullable=False)
    code = Column(String(255), nullable=False)
    situation = Column(String(255), nullable=False)
    dish = Column(String(255), nullable=False)
    special = Column(Text)
    solid_percent = Column(String(255), nullable=False)
    usage = Column(String(255), nullable=False)
    best_use = Column(String(255), nullable=False)
    price = Column(String(255), nullable=False)
    unit = Column(String(255), nullable=False)
    promote = Column(String(255), nullable=False)
    location = Column(String(255), nullable=False)

    def to_json(self):
        dict = self.__dict__
        if "_sa_instance_state" in dict:
            del dict["_sa_instance_state"]
        return dict

class UFSDishes(Base):
    __tablename__='ufs_dish_detail'

    dish_id=Column(Integer,primary_key=True)
    dish_src=Column(String(255),nullable=False)
    dish_name = Column(String(255), nullable=False)
    tags = Column(String(255), nullable=False)
    ishot = Column(Integer, nullable=False)
    swiper = Column(Integer, nullable=False)
    introduce = Column(Integer, nullable=False)

    def to_json(self):
        dict = self.__dict__
        if "_sa_instance_state" in dict:
            del dict["_sa_instance_state"]
        return dict

class ProductsByShape(Base):
    __tablename__='products_by_shape'

    id=Column(Integer,primary_key=True)
    product_name=Column(String(255),nullable=False)
    product_code = Column(String(255), nullable=False)
    shape = Column(String(255), nullable=False)
    taste = Column(String(255), nullable=False)
    desc = Column(String(255), nullable=False)
    introduce = Column(String(255), nullable=False)

    def to_json(self):
        dict = self.__dict__
        if "_sa_instance_state" in dict:
            del dict["_sa_instance_state"]
        return dict

class SixLinesProducts(Base):
    __tablename__='6_lines_products'

    id=Column(Integer,primary_key=True)
    one=Column(String(255),nullable=False)
    two = Column(String(255), nullable=False)
    three = Column(String(255), nullable=False)
    taste = Column(String(255), nullable=False)
    product_name = Column(String(255), nullable=False)
    product_code = Column(String(255), nullable=False)

    def to_json(self):
        dict = self.__dict__
        if "_sa_instance_state" in dict:
            del dict["_sa_instance_state"]
        return dict

# 根据味型匹配基础应用的抽象类
class BasicMatches(Base):
    __tablename__='test-basic_matches'

    id=Column(Integer,primary_key=True)
    smell_taste=Column(String(255),nullable=False)
    com_code = Column(String(255), nullable=False)
    matches = Column(String(255), nullable=False)
    inner_code = Column(String(255), nullable=False)
    inner_name = Column(String(255), nullable=False)
    issmell = Column(String(255), nullable=False)
    istaste = Column(String(255), nullable=False)
    smell_desc = Column(String(255), nullable=False)
    suggested_usage = Column(String(255), nullable=False)
    pro_shape = Column(String(255), nullable=False)
    solubility = Column(String(255), nullable=False)
    cost = Column(String(255), nullable=False)
    taste = Column(String(255), nullable=False)
    fir_level = Column(String(255), nullable=False)
    sec_level = Column(String(255), nullable=False)
    ismatch = Column(String(255), nullable=False)
    ismain = Column(String(255), nullable=False)
    main_ingr = Column(String(255), nullable=False)
    special = Column(String(255), nullable=False)
    smell_taste_desc = Column(String(255), nullable=False)

    def to_json(self):
        dict = self.__dict__
        if "_sa_instance_state" in dict:
            del dict["_sa_instance_state"]
        return dict

#     TFC是taste、food、cook的三种匹配的菜品抽象类
# $$$$$$$$$$$$$$$$$$$$$$$$$下班了，抽象类写完，下周完善后续的菜品展示
class TFCMatchDish(Base):
    __tablename__='testdata_smell+cook+food+dish'

    id=Column(Integer,primary_key=True)
    smell=Column(String(255),nullable=False)
    cook = Column(String(255), nullable=False)
    food = Column(String(255), nullable=False)
    name = Column(String(255), nullable=False)
    pic = Column(String(255),nullable=False)
    mainIngrs = Column(JSON, nullable=False)
    juhui_pro=Column(JSON,nullable=False)
    tags = Column(JSON, nullable=False)
    steps = Column(JSON, nullable=False)

    def to_json(self):
        dict = self.__dict__
        if "_sa_instance_state" in dict:
            del dict["_sa_instance_state"]
        return dict

class DishDetail(Base):
    __tablename__='ufs_dishes_detail'

    dish_id=Column(Integer,primary_key=True)
    dish_pic_src=Column(String(255),nullable=False)
    dish_name = Column(String(255), nullable=False)
    dish_tags = Column(String(255), nullable=False)
    dish_special = Column(String(255), nullable=False)
    dish_from = Column(String(255), nullable=False)
    dish_main = Column(JSON, nullable=False)
    dish_little = Column(JSON, nullable=False)
    dish_spicy = Column(JSON, nullable=False)
    cooking_methods = Column(JSON,nullable=False)

    def to_json(self):
        dict = self.__dict__
        if "_sa_instance_state" in dict:
            del dict["_sa_instance_state"]
        return dict

class MTCustomers(Base):
    __tablename__='mt_all_customers'

    shop_name=Column(String(50),nullable=False,primary_key=True)
    shopper_name = Column(String(50), nullable=False)
    chain = Column(String(10), nullable=False)
    business_district = Column(String(20), nullable=False)
    area = Column(String(30), nullable=False)
    city = Column(String(30), nullable=False)
    province = Column(String(30), nullable=False)
    rate = Column(String(30), nullable=False)
    rate_times = Column(String(30), nullable=False)
    ave_price = Column(String(30), nullable=False)
    catering_class = Column(String(30), nullable=False)

    def to_json(self):
        dict = self.__dict__
        if "_sa_instance_state" in dict:
            del dict["_sa_instance_state"]
        return dict


# 基于美团数据分析商家的优劣势
# 前台：地址+类目（重庆市重庆市北碚区蔡家，1、该区同类型门店数量---竞争性；2、评价数、评价分、价格在同区的水平---现状；）-----竞争得分：85分
#      菜单（食材占比、味型占比、价格分布、烹饪方式占比）结合目标人群特点------需求满足匹配度：90分
#




